﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Configuration.ServerApi.Param;
using Configuration.ServerApi.Service;
using System.Threading.Tasks;

namespace Configuration.ServerApi.Controllers
{
    /// <summary>
    /// 实验任务相关Controller
    /// </summary>
    [Authorize("AuthJwt")]
    [Route("api/[controller]")]
    [ApiController]
    public class ExperimentController : ControllerBase
    {
        private readonly IHostEnvironment HostEnvironment;
        private readonly IExperimentService ExperimentService;

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="hostEnvironment"></param>
        /// <param name="experimentService"></param>
        public ExperimentController(IHostEnvironment hostEnvironment,
            IExperimentService experimentService)
        {
            HostEnvironment = hostEnvironment;
            ExperimentService = experimentService;
        }

        #endregion

        #region 检查实验任务队列

        /// <summary>
        /// 检查实验任务队列
        /// </summary>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("CheckExperimentQueue")]
        public async Task<IActionResult> CheckExperimentQueue()
        {
            return await ExperimentService.CheckExperimentQueue();
        }

        #endregion

        #region 生成实验任务编号

        /// <summary>
        /// 生成实验任务编号
        /// </summary>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("CreateExperimentNumber")]
        public async Task<IActionResult> CreateExperimentNumber()
        {
            return await ExperimentService.CreateExperimentNumber();
        }

        #endregion

        #region 获取实验统计数据

        /// <summary>
        /// 获取实验统计数据
        /// </summary>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("ExperimentStatistics")]
        public async Task<IActionResult> ExperimentStatistics()
        {
            return await ExperimentService.ExperimentStatistics();
        }

        #endregion

        #region 获取当前实验预计完成时长

        /// <summary>
        /// 获取当前实验预计完成时长
        /// </summary>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("GetThisExpectedCompletionTime")]
        public async Task<IActionResult> GetThisExpectedCompletionTime()
        {
            return await ExperimentService.GetThisExpectedCompletionTime();
        }

        #endregion

        #region 获取累计实验工作时长

        /// <summary>
        /// 获取累计实验工作时长
        /// </summary>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("Accumulateworkduration")]
        public async Task<IActionResult> Accumulateworkduration()
        {
            return await ExperimentService.Accumulateworkduration();
        }

        #endregion

        #region 获取实验模板列表

        /// <summary>
        /// 获取实验模板列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("ExperimentTemplateList")]
        public async Task<IActionResult> ExperimentTemplateList(SearchModel param)
        {
            return await ExperimentService.ExperimentTemplateList(param);
        }

        #endregion

        #region 获取实验模板详情

        /// <summary>
        /// 获取实验模板详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("ExperimentTemplateDetail")]
        public async Task<IActionResult> ExperimentTemplateDetail(SearchModel param)
        {
            return await ExperimentService.ExperimentTemplateDetail(param);
        }

        #endregion

        #region 提交实验模板信息

        /// <summary>
        /// 提交实验模板信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("SubmitExperimentTemplate")]
        public async Task<IActionResult> SubmitExperimentTemplate(UpdateModel param)
        {
            return await ExperimentService.SubmitExperimentTemplate(param);
        }

        #endregion

        #region 批量删除实验模板信息

        /// <summary>
        /// 批量删除实验模板信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("DelExperimentTemplate")]
        public async Task<IActionResult> DelExperimentTemplate(UpdateModel param)
        {
            return await ExperimentService.DelExperimentTemplate(param);
        }

        #endregion

        #region 更新实验模板顺序

        /// <summary>
        /// 更新实验模板顺序
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("UpdateExperimentTemplateSort")]
        public async Task<IActionResult> UpdateExperimentTemplateSort(UpdateModel param)
        {
            return await ExperimentService.UpdateExperimentTemplateSort(param);
        }

        #endregion

        #region 获取实验模板关联配置列表

        /// <summary>
        /// 获取实验模板关联配置列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("ExperimentTemplateConfigList")]
        public async Task<IActionResult> ExperimentTemplateConfigList(SearchModel param)
        {
            return await ExperimentService.ExperimentTemplateConfigList(param);
        }

        #endregion

        #region 获取实验模板关联配置详情

        /// <summary>
        /// 获取实验模板关联配置详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("ExperimentTemplateConfigDetail")]
        public async Task<IActionResult> ExperimentTemplateConfigDetail(SearchModel param)
        {
            return await ExperimentService.ExperimentTemplateConfigDetail(param);
        }

        #endregion

        #region 提交实验模板关联配置信息

        /// <summary>
        /// 提交实验模板关联配置信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("SubmitExperimentTemplateConfig")]
        public async Task<IActionResult> SubmitExperimentTemplateConfig(UpdateModel param)
        {
            return await ExperimentService.SubmitExperimentTemplateConfig(param);
        }

        #endregion

        #region 批量删除实验模板关联配置信息

        /// <summary>
        /// 批量删除实验模板关联配置信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("DelExperimentTemplateConfig")]
        public async Task<IActionResult> DelExperimentTemplateConfig(UpdateModel param)
        {
            return await ExperimentService.DelExperimentTemplateConfig(param);
        }

        #endregion

    }
}
